package main

import (
	"flag"
	"fmt"
	"os"
	"strconv"
	"strings"
	"tempconv"
)

const boilingF = 212.0

func boiling() {
	var f = boilingF
	var c = (f - 32) * 5 / 9
	fmt.Printf("boiling point - %g°F or %g°C\n", f, c)
}

func fToc(f float64) float64 {
	return (f - 32) * 5 / 9
}

func fTocTest() {
	const freezingF, boilingF = 32.0, 212.0
	fmt.Printf("%g°F = %g°C\n", freezingF, fToc(freezingF))
	fmt.Printf("%g°F = %g°C\n", boilingF, fToc(boilingF))
}

func incr(p *int) int {
	*p++
	return *p
}

func incrTest() {
	v := 1
	incr(&v)
	fmt.Println(incr(&v))
}

var n = flag.Bool("n", false, "omit trailing newling")
var sep = flag.String("s"," ", "separator")

func echo4() {
	flag.Parse()
	fmt.Print(strings.Join(flag.Args(), *sep))
	if !*n{
		fmt.Print()
	}
}

type Celsius 	float64		//摄氏温度
type Fahrenheit float64		//华氏温度

const  (
	AbsoluteZeroC	Celsius = -273.15
	FreezingC		Celsius = 0
	BoilingC		Celsius = 100
)

func CToF(c Celsius) Fahrenheit  {
	return Fahrenheit(c*9/5 + 32)
}

func FToC(f Fahrenheit) Celsius {
	return Celsius((f-32)*5/9)
}

func testType() {
	fmt.Printf("%g\n", BoilingC - FreezingC)
	boilingF := CToF(BoilingC)
	fmt.Printf("%g\n", boilingF - CToF(FreezingC))

}

func importTest() {
	for _, arg := range os.Args[1:]{
		t, err := strconv.ParseFloat(arg, 64)
		if err!=nil {
			fmt.Fprintf(os.Stderr, "cf: %v\n", err)
			os.Exit(1)
		}
		f := tempconv.Fahrenheit(t)
		c := tempconv.Celsius(t)
		fmt.Printf("%s = %s, %s = %s\n",
			f, tempconv.FToC(f), c, tempconv.CToF(c))
	}
}

func main() {
	//boiling()
	//fTocTest()
	//incrTest()
	//echo4()
	//testType()
	importTest()
}
